package com.dycc.libary.http.interceptor;

import android.content.Context;
import android.util.Log;

import java.io.IOException;

import io.reactivex.Flowable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author  吴学坤
 * 注解：向请求中添加cookie 拦截器
 */

public class RequestCookiesInterceptor implements Interceptor {

    private Context context;

    public RequestCookiesInterceptor(Context context) {
        super();
        this.context = context;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        final Request.Builder builder = chain.request().newBuilder();
        String cookie = "";
        Log.v("cookiel",cookie);
        Flowable.just(cookie)
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(@NonNull String cookie) throws Exception {
                        //添加cookie
                        builder.addHeader("cookie", cookie);
//                        //自动登录

                    }
                });

        Response response=chain.proceed(builder.build());
        return response;
    }

}
